<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head th:fragment="head">
	<base th:href="@{/}">
	<meta charset="utf-8">
	<title>新增</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="static/layui/css/layui.css" media="all" />
	<script type="text/javascript" src="static/layui/layui.all.js"></script>
	<script type="text/javascript" src="static/plugin/jquery/jquery-3.2.1.min.js"></script>
</head>
<body class="layui-fluid" th:fragment="body">
<div class="layui-row">
	<div class="layui-col-md12">
		<form class="layui-form" lay-filter="formDemo" id="form" action="" style="padding-top: 20px;">
			<div class="layui-form-item">
				<label class="layui-form-label">供应商编码</label>
				<div class="layui-input-block">
					<input type="text" name="cusCode" lay-verify="required"  id="cusCode" placeholder="请输入供应商编码" autocomplete="off" class="layui-input" >
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">供应商名称</label>
				<div class="layui-input-block">
					<input type="text" name="cusName" lay-verify="required"  id="cusName" placeholder="请输入供应商名称" autocomplete="off" class="layui-input" >
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">料号</label>
				<div class="layui-input-block">
					<input type="text" name="material" lay-verify="required"  id="material" placeholder="请输入" autocomplete="off" class="layui-input" >
					<input type="text" name="classType" hidden="hidden"  id="classType">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">标准值</label>
				<div class="layui-input-block">
					<input type="number" min="0" name="standard" required  lay-verify="required" placeholder="请输入外验最低库存" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">增长值</label>
				<div class="layui-input-block">
					<input type="number" min="0" name="growUp" required  lay-verify="required" placeholder="请输入不良品最低库存" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">仓库</label>
				<div class="layui-input-block">
					<input type="text" name="storeName" hidden="hidden"  id="storeName">
					<select name="storeType" id="storeType" lay-filter="demo-select-filter">
						<option value="">请选择</option>
						<optgroup label="产成品">
							<option value="ok">外验ok</option>
							<option value="error">不良品重工</option>
							<option value="wait">待验</option>
						</optgroup>
						<optgroup label="其他" >
							<option value="B">半成品</option>
							<option value="C">辅材</option>
							<option value="D">原材料</option>
							<option value="E">低耗</option>
							<option value="F">包材</option>
							<option value="G">杂项</option>
							<option value="H">塑件</option>
							<option value="I">油漆</option>
						</optgroup>
					</select>
				</div>
			</div>
		</form>
	</div>
</div>
<script type="text/javascript">
	layui.config({
		base: "static/layui/"
	}).extend({
		tableSelect: 'tableSelect'
	}).use(['form', 'layer', 'jquery', 'table', 'laydate', 'upload','tableSelect'], function () {
		var form = layui.form;
		var tableSelect = layui.tableSelect;

		form.render()

		tableSelect.render({
			elem: '#cusCode',
			checkedKey: 'cusCode',
			searchPlaceholder: '企业编码',
			searchKey: 'cusCode',
			table: {
				url: 'manage/common/list/customer'
				,method: 'post'
				,cols: [
					[
						{ type: 'radio' },
						{ field: 'cusCode', title: '企业编码' },
						{ field: 'cusName', title: '企业名称' },
					]
				]
			},
			done: function (elem, data) {
				var NEWJSON = []
				var NEWJSONName = []
				layui.each(data.data, function (index, item) {
					NEWJSON.push(item.cusCode)
					NEWJSONName.push(item.cusName)
				})
				elem.val(NEWJSON.join(","))
				$("#cusName").val(NEWJSONName.join(","))
			}
		})

		tableSelect.render({
			elem: '#material',
			checkedKey: 'invCode',
			searchPlaceholder: '料号编码',
			searchKey: 'invCode',
			table: {
				url: 'base_material/djBaseList',
				cols: [
					[
						{ type: 'radio' },
						{ field: 'invCode',hide: true ,
							templet: function (e) {
								return e.djMaterial
							}
						},
						{ field: 'djMaterial',width: 150, title: '料号编码' },
						{ field: 'cusMaterial',width: 150, title: '客户料号' },
						{ field: 'materialMrk',width: 150, title: '料号名称' },
						{ field: 'cusCode',width: 100, title: '企业编码' },
						{ field: 'cusName',width: 150, title: '企业名称' },
					]
				]
			},
			done: function (elem, data) {
				var NEWJSON = []
				var types = []
				layui.each(data.data, function (index, item) {
					NEWJSON.push(item.djMaterial)
					types.push(item.classType)
				})
				form.val("formDemo", {
					"storeType": types.join(","),
					"classType": types.join(",")
				});
				$("#storeName").val($("#storeType").find("option:selected").text());
				elem.val(NEWJSON.join(","))
			}
		})

		form.on('select(demo-select-filter)', function(data){
			$("#storeName").val(this.innerHTML)
		});

	})

	function getFormDataAndValidate(){
		var data = $('#form').serializeArray();
		var obj = new Object();
		$.each(data, function(index, e){
			obj[e.name] = e.value;
		})
		return [true,obj];
	}
</script>
</body>
</html>